using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class PatientPayerMap : EntityTypeConfiguration<PatientPayer>
	{
		public PatientPayerMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.PayerName)
				.HasMaxLength(50);
				
			this.Property(t => t.InsuranceNumber)
				.HasMaxLength(50);
				
			this.Property(t => t.EmployeeNumber)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("PatientPayers");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.PatientId).HasColumnName("PatientId");
			this.Property(t => t.PayerName).HasColumnName("PayerName");
			this.Property(t => t.ValidFrom).HasColumnName("ValidFrom");
			this.Property(t => t.ValidTo).HasColumnName("ValidTo");
			this.Property(t => t.InsuranceNumber).HasColumnName("InsuranceNumber");
			this.Property(t => t.EmployeeStatus).HasColumnName("EmployeeStatus");
			this.Property(t => t.EmployeeNumber).HasColumnName("EmployeeNumber");
			this.Property(t => t.BankId).HasColumnName("BankId");
			this.Property(t => t.InsuranceId).HasColumnName("InsuranceId");
			this.Property(t => t.CorporatePayerId).HasColumnName("CorporatePayerId");

			// Relationships
			this.HasOptional(t => t.Bank)
				.WithMany(t => t.PatientPayers)
				.HasForeignKey(d => d.BankId);
				
			this.HasOptional(t => t.Insurance)
				.WithMany(t => t.PatientPayers)
				.HasForeignKey(d => d.InsuranceId);
				
			this.HasRequired(t => t.Patient)
				.WithMany(t => t.PatientPayers)
				.HasForeignKey(d => d.PatientId);
				
		}
	}
}

